﻿using Artemis;
using libtcod;
using RL.Components;

namespace RL.Systems
{
    public class RenderConsoleSystem : EntityProcessingSystem
    {
        private ComponentMapper<ScreenBuffer> _screenBufferMapper;

        /// <summary>
        /// Initializes a new instance of the <see cref="RenderConsoleSystem"/> class.
        /// Draws a screen buffer to the console.
        /// </summary>
        public RenderConsoleSystem() : base(typeof(ScreenBuffer))
        {            
        }

        public override void Initialize()
        {
            _screenBufferMapper = new ComponentMapper<ScreenBuffer>(world);
        }

        public override void Process(Artemis.Entity e)
        {
            var buffer = _screenBufferMapper.Get(e);
            TCODConsole.blit(buffer.Console, 0, 0, buffer.Console.getWidth(), buffer.Console.getHeight(), TCODConsole.root, buffer.Position.X, buffer.Position.Y);
        }
    }
}